#include "gtest/gtest.h"
#include "MessageHandler.h"
#include <thread>

#define EVENT_TEST_MSG   1


static void testHandlerMessage(Message* msg) {
    switch(msg->what) {
        case EVENT_TEST_MSG: {
            ASSERT_TRUE(TRUE);
            Handler* handler = (Handler*)msg->userObj;
            quit(handler->mQueue);
            break;
        }
        default:
            ASSERT_TRUE(FALSE);
            break;
    }
}



TEST(MessageTest, HandleMessageTest) {
    prepare(TRUE);
    Handler* handler = newHandler(testHandlerMessage);

    std::thread thread = std::thread([handler, this]() {
        Message* msg = handlerObtainMessage(handler, EVENT_TEST_MSG, NULL);
        msg->userObj = handler;
        messageSendToTarget(msg);
    });
    loop();
    deleteHandler(handler);
    thread.join();
}

